﻿$.datepicker.setDefaults({
	closeText: "Klaar", // Display text for close link
	prevText: "Vorige", // Display text for previous month link
	nextText: "Volgende", // Display text for next month link
	currentText: "Vandaag", // Display text for current month link
	monthNames: ["Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"], // Names of months for drop-down and formatting
	monthNamesShort: ["Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"], // For formatting
	dayNames: ["Zondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag"], // For formatting
	dayNamesShort: ["Zon", "Maa", "Din", "Woe", "Don", "Vrij", "Zat"], // For formatting
	dayNamesMin: ["Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za"], // Column headings for days starting at Sunday
	weekHeader: "Wk", // Column header for week of the year
	dateFormat: "dd-mm-yy", // See format options on parseDate
	firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
	isRTL: false, // True if right-to-left language, false if left-to-right
	showMonthAfterYear: false, // True if the year select precedes month, false for month then year
	yearSuffix: "" // Additional text to append to the year in the month headers
});

$G.web = {
	reformatTooltip: function (elt) {
		var tooltipContent = elt.prop('title').replaceAll('|', '<br />');
		var deviceAgent = navigator.userAgent.toLowerCase();
		if (deviceAgent.match(/(iphone|ipod|ipad)/))
			tooltipContent = "<div style='width:100%;text-align:right;'><a href=\"javascript:$('#" + elt.prop('id') + "').tooltip('close');\"><img src=\"/Images/tooltipclose.png\"></a></div>" + tooltipContent;

		return tooltipContent;
	}
};

$G.web.dialog =	{
		show: function (d, args) {
			var dialog = $G.web.dialogs[d];
			$.each(dialog, function (key, form) {
				if (form.buttons) { //is it a form?
					form.key = key;
					form.dialog = dialog;
					form.submit = function (e, v, m, f) { return $G.web.dialog.submit(e, v, m, f, form); };
					$G.web.dialog.reshapeHtml(form);
				}
			});

			$.prompt(dialog, { top: "5%", loaded: function () { $G.web.dialog.loaded(dialog, args); }, statechanging: function (e, fromStateName, toStateName) { $G.web.dialog.statechanging(dialog, fromStateName, toStateName); } });
		},

		reshapeHtml: function (form) {
			if (form.html.indexOf('clientside-dialog') >= 0)
				return;

			form.html = $G.string.format('<div class="clientside-dialog" id="form_{#0}">' +
						'<div id="{#0}gollie_imp_errormsg" style="display:none; font-size: 0.9em; background-color: #f6f6f6; border: 1px solid #d0d0d0; margin-bottom: 8px; padding: 4px;">' +
						'<span class="error"></span></div>{#1}</div>'
						, form.key, form.html);
		},

		statechanging: function (dialog, fromStateName, toStateName) {
			var form = dialog[toStateName];
			var jqoFrom = $.prompt.getState(fromStateName);
			var jqoTo = $.prompt.getState(toStateName);

			$('#' + form.key + 'gollie_imp_errormsg').hide();

			if (form.preparehtml) {
				form.preparehtml(dialog, $.prompt.getState(fromStateName), $.prompt.getState(toStateName));
			}
		},

		loaded: function (dialog, args) {
			$('.jqifade').remove(); $('.jqibox').prepend('<div class="impromptu-fade"/>');
			$('.dialog-datepicker').each(function(index) {
				if ($(this).hasClass('birthdate')) {
					$(this).datepicker({ changeMonth: true, changeYear: true, yearRange: "-100:-18" });
					if ($(this).val().length == 0) $(this).datepicker("setDate", "1/1/1980");
				}
			})
			if (typeof args != 'undefined') {
				$.each(args, function (key, value) {
					var elt = $(key);
					if (elt.is("label") || elt.is("span")) elt.text(value);
					else if (elt.is("input")) elt.val(value);
					else elt.html(value);
				});
			}

			$('.clientside-dialog input').each(function (index) {
				if ($(this).hasClass('markasrequired')) {
					$(this).after('<span style="color: red; margin-left: 2px; margin-right: 4px;">*</span>');
				}
			})
		},

		replaceDialog: function (d) {
			$.prompt.close();
			window.setTimeout($G.web.dialog.show, 500, d);
		},

		buttons: {
			OkCancel: { OK: 1, Annuleren: 0 },
			Ok: { OK: 1 },
			Close: { Sluiten: 1 },
			NextCancel: { "Volgende...": 1, Annuleren: 0 },
			PreviousNextCancel: { "Vorige...": -1, "Volgende...": 1, Annuleren: 0 },
			PreviousSaveCancel: {"Vorige...": -1,  Opslaan: 1, Annuleren: 0 },
			SaveCancel: { Opslaan: 1, Annuleren: 0 }
		},

		submit: function (e, v, m, f, form) {
			if (v == 0) return true; //cancel
			if (v == 1) {
				var errors = [];
				if (form.clientValidate) {
					errors = form.clientValidate(f);
					if (errors.length > 0) $G.web.dialog.clientValidationFail(errors, form);
				}

				if (errors.length == 0) {
					if (form.ajaxCall) {
						var ajaxArgs = {};
						if (form.ajaxArg) ajaxArgs = form.ajaxArg(f);
						$G.web.ajax[form.ajaxCall](ajaxArgs, function (msg) { $G.web.dialog.success(msg, form, f) }, function (msg) { $G.web.dialog.fail(msg, form) });
					}
					else
						$G.web.dialog.success(undefined, form, f);
				}
			}
			else {
				if (v == -1) {
					if (form.previousState)
						$.prompt.goToState(form.previousState);
				}
				else {
					if (form.submitCustomButton) {
						return form.submitCustomButton(f, v);
					}
					else
						throw "Unhandled button click: " + v.toString();
				}
			}
				
			return false;
		},

		clientValidate: function (f, errors) {
			var curState = $.prompt.getCurrentState();

			$('.validate', curState).each(function (index) {
				var v = getVals($(this));
				if ($(this).hasClass('required')) {
					if (v.value.length == 0) errors.push(v.friendlyname + ' niet ingevuld');
				}
				if ($(this).hasClass('lengthrange')) {
					if (v.value.length < v.minlength || v.value.length > v.maxlength) errors.push($G.string.format('{#0} moet minimaal {#1} en maximaal {#2} karakters bevatten', v.friendlyname, v.minlength, v.maxlength));
				}
				if ($(this).hasClass('minlength')) {
					if (v.value.length < v.minlength) errors.push($G.string.format('{#0} moet minimaal {#1} karakters bevatten', v.friendlyname, v.minlength));
				}
				if ($(this).hasClass('regex')) {
					var valmsg = 'ongeldig';
					if (v.validationmsg !== undefined) valmsg = v.validationmsg;
					if (v.regex.test(v.value) == false) errors.push(v.friendlyname + ' ' + valmsg);
				}
			});

			function getVals(jqO) {
				var n = jqO.attr('name'), minl = jqO.attr('minlength'), maxl = jqO.prop('maxlength'), reg = jqO.attr('regex'), val = f[n].trim(), valmsg = jqO.attr('validationmsg');
				return { name: n, friendlyname: jqO.attr('friendlyname'), minlength: minl && Number(minl), maxlength: maxl && Number(maxl), regex: reg && new RegExp(reg), validationmsg: valmsg, value: val };
			}
		},

		clientValidationFail: function (errors, form) {
			var errHtml = '<ul>';
			$.each(errors, function (i, v) { errHtml += ('<li>' + v + '</li>'); })
			errHtml += '</ul>';
			$G.web.dialog.fail({ errorMessage: errHtml }, form);
		},

		success: function (msg, form, f) {
			if (form.nextStateOnSuccess) {
				if (form.nextStateOnSuccess.replacedialog)
					if ($.isFunction(form.nextStateOnSuccess.replacedialog))
						$G.web.dialog.replaceDialog(form.nextStateOnSuccess.replacedialog(f));
					else
						$G.web.dialog.replaceDialog(form.nextStateOnSuccess.replacedialog);
				else {

					if (form.nextStateOnSuccess.slice(0, 1) == "/" || form.nextStateOnSuccess.slice(0, 4) == "http") {
						$.prompt.close();
						window.location = form.nextStateOnSuccess;
					}
					else {
						if (msg)
							msg.state = 0;

						form.dialog[form.nextStateOnSuccess].msg = msg;
						$.prompt.goToState(form.nextStateOnSuccess);
					}
				}
			}
			else {
				$.prompt.close();
				if (form.reload != false) {
					if (window.location.pathname.indexOf('xpired.aspx') >= 0)
						window.location = '/Default.aspx';
					else
						window.location.search += '&' + Math.random(); // Make sure it's a first hit, instead of a postback. Postback happens on 'reload(true)';
				}
			}
		},

		fail: function (msg, form) {
			$('#form_' + form.key).scrollTop(0);
			var ed = $('#' + form.key + 'gollie_imp_errormsg');
			$('.error', ed).html(msg.errorMessage);
			$(ed).slideUp("fast").slideDown("fast");
		},

		helpers: {
			input2label: function (jqoFrom, jqoTo, elts) {
				$.each(elts, function (key, value) {
					var target = $(value, jqoTo);
					target.text($(key, jqoFrom).val());
				});
			},

			input2input: function (jqoFrom, jqoTo, elts) {
				$.each(elts, function (key, value) {
					var target = $(value, jqoTo);
					if (target.val().length == 0)
						target.val($(key, jqoFrom).val());
				});
			}
		}
	}

$G.web.dialoghtml = {
	login: $G.string.format('<table>' +
			'<tr><td><span>{#0}</span></td><td><input class="validate required markasrequired" friendlyname="{#0}" name="username" type="text" maxlength="16" placeholder="gebruikersnaam"></td></tr>' +
			'<tr><td><span>{#1}</span></td><td><input class="validate minlength markasrequired" friendlyname="{#1}" minlength="6" name="ww" type="password" placeholder="wachtwoord"></td></tr>' +
			'<tr><td colspan="2" style="text-align: left; padding-top: 4px;"><div style="font-size: 0.8em; float: left; margin-left: 16px; border: 1px dotted #606060;"><a class="common" href="#" onclick="$G.web.dialogs.login.form.resetWW();">{#1} vergeten...</a></div></td></tr>' +
			'</table>', 'Gebruikersnaam', 'Wachtwoord')
			,
	resetWW: $G.string.format('<span style="font-size: 0.9em">Vul uw gebruikersnaam in en druk op OK. U krijgt dan over enkele ogenblikken een nieuw wachtwoord in uw mailbox.<br/></span>' +
			'<table><tr><td>' +
			'<span>{#0}</span></td><td>' +
			'<input class="validate required markasrequired" friendlyname="{#0}" name="username" type="text" maxlength="16" placeholder="gebruikersnaam">' +
			'</td></tr></table>', 'Gebruikersnaam')
			,
	resetWWConfirm: '<span>Een nieuw wachtwoord is zojuist naar uw e-mailadres verzonden.</span>'
			,
	registerObj: $G.string.format('<div style="font-size: 0.9em;">' +
			'<span class="explanation" style="color: #008000;"><b>Registreer als consument</b> als u gebruikt wilt maken van de deals welke door ondernemingen worden aangeboden. U krijgt een Gollie-code waarmee u, middels uw smartphone, uw bestedingen kunt afrekenen.<br/><br/><b>Registreer als onderneming</b> als u met uw onderneming deals wil aanbieden aan consumenten.<br/></span>' +
			'<hr/>' +
			'<span style="font-size: 1.1em; font-weight: bold; display: block; margin-bottom: 8px;">Ik registreer als:</span>' +
			'<input type="radio" name="{#0}" id="{#1}" value="1" checked="checked"><label for="{#1}">Consument</label><br/>' + 
			'<input type="radio" name="{#0}" id="{#2}" value="2"><label for="{#2}">Onderneming</label>' +
			'</table></div>', 'rbregoption', 'rbregconsumer', 'rbregbusiness')
			,
	registerConsumer: $G.string.format(
			'<div style="font-size: 0.9em;">' +
			'<table>' +
			'<tr><td><label for="{#0}">{#1}</label></td><td><input class="validate required markasrequired" friendlyname="{#1}" name="{#0}" id="{#0}" type="text" maxlength="16"></td></tr>' +
			'<tr><td><label for="{#2}">{#3}</label></td><td><input name="{#2}" id="{#2}" type="text" maxlength="16"></td></tr>' +
			'<tr><td><label for="{#4}">{#5}</label></td><td><input class="validate required markasrequired" friendlyname="{#5}" name="{#4}" id="{#4}" type="text" maxlength="48"></td></tr>' +
			'<tr><td><label for="{#6}">{#7}</label></td><td><input class="validate required markasrequired" friendlyname="{#7}" name="{#6}" id="{#6}" type="text" maxlength="32"></td></tr>' +
			'<tr><td><label for="{#8}">{#9}</label></td><td><input type="radio" name="{#8}" id="{#10}" value="1" checked="checked"><label for="{#10}">Man</label><input type="radio" name="{#8}" id="{#11}" value="0"><label for="{#11}">Vrouw</label></td></tr>' +
			'<tr><td><label for="{#12}">{#13}</label></td><td><input class="validate regex dialog-datepicker birthdate markasrequired" regex="^\\d{2}-\\d{2}-\\d{4}$" validationmsg="formaat: dd-mm-jjjj" friendlyname="{#13}" name="{#12}" id="{#12}" type="text"></td></tr>' +
			'<tr><td><label for="{#14}">{#15}</label></td><td><input class="validate regex markasrequired" regex="^[^@]+@[^\\.@]+\\..+$" friendlyname="{#15}" name="{#14}" id="{#14}" type="text" maxlength="128"></td></tr>' +
			'<tr><td><label for="{#16}">{#17}</label></td><td><input class="validate regex markasrequired" regex="^(00316|\\+316|06)[- ]?\\d{8}$" friendlyname="{#17}" name="{#16}" id="{#16}" type="text"></td></tr>' +
			'<tr><td><label for="{#18}">{#19}</label></td><td><input class="validate lengthrange markasrequired" friendlyname="Gebruikersnaam" minlength="6" name="{#18}" id="{#18}" type="text" maxlength="16" placeholder="max 16 karakters"></td></tr>' +
			'<tr><td><label for="{#20}">{#21}</label></td><td><input class="validate minlength markasrequired" minlength="6" friendlyname="Wachtwoord" name="{#20}" id="{#20}" type="password" placeholder="min 6 karakters"></td></tr>' +
			'<tr><td><label for="{#22}">{#23}</label></td><td><input class=" markasrequired" name="{#22}" id="{#22}" type="password" placeholder="min 6 karakters"></td></tr>' +
			'<tr><td colspan="2" class="wrap" style="padding-top: 10px; padding-bottom: 4px;"><span style="color: #c00000; font-size: 1.1em;">LET OP: U heeft uw pincode nodig bij het afrekenen in de winkel. Onthoud deze dus goed.</span><br /></td></tr>' +
			'<tr><td><label for="{#24}">{#25}</label></td><td><input class="validate regex markasrequired" regex="^\\d{4}$" validationmsg="moet uit 4 cijfers bestaan" friendlyname="Pincode" name="{#24}" id="{#24}" type="password" maxlength="4" placeholder="0000"></td></tr>' +
			'<tr><td><label for="{#26}">{#27}</label></td><td><input class=" markasrequired" name="{#26}" id="{#26}" type="password" maxlength="4" placeholder="0000"></td></tr>' +
			'<tr><td></td><td class="wrap"><input name="cbconditions" id="cbconditions" type="checkbox"><span>Ik ga akkoord met&nbsp;</span><a class="common" href="/ConsumerConditions.aspx" target="_blank">de voorwaarden.</a></td></tr>' +
			'</table></div>', 'tbvoorletters', 'Voorletters', 'tbtussenvoegsel', 'Tussenvoegsel', 'tbachternaam', 'Achternaam', 'tbwoonplaats', 'Woonplaats', 'rbsex', 'Geslacht', 'rbman', 'rbvrouw', 'tbgeboortedatum', 'Geboortedatum', 'tbemail', 'E-mail', 'tbmobile', 'Mobiel', 'tbusername', 'Kies uw gebruikersnaam', 'tbww', 'Kies uw wachtwoord', 'tbwwrepeat', 'Wachtwoord nogmaals', 'tbpin', 'Kies uw 4-cijferige pincode', 'tbpinrepeat', 'Pincode nogmaals')
			,
	registersuccess: '<span>U bent geregistreerd bij Gollie.nl.</span><br/>' +
					'<div style="background-color: #f6f6f6; border: 1px solid #d0d0d0; font-size: 1.2em; margin-bottom: 1em; margin-top: 1em; padding: 8px;">' +
					'<span>Let op!<br/><br/>U dient uw lidmaatschap nog te activeren.</span>' +
					'</div>' +
					'<span>Om uw lidmaatschap te activeren is een e-mail verstuurd naar het door u opgegeven e-mailadres. Deze e-mail bevat een link naar de activeringspagina van Gollie.nl. Zodra u op deze link klikt, is de registratie voltooid.<br/>' +
					'<br/>' +
					'<span>Onder normale omstandigheden kunt u de e-mail over enkele ogenblikken in uw inbox verwachten.</span>'
			,
	changeprofile: $G.string.format(
			'<div style="font-size: 0.9em; display: none;" id="pnlchangeprofile">' +
			'<div style="text-align: center;"><table style="display:inline;"><tr class="customer"><td style="vertical-align: middle;">' +
			'<a href="/ViewQR.aspx" target="_blank" title="Klik om de Gollie-code in een nieuw venster te openen">' +
			'<img id="imgQRThumbnail" src="" height="37" width="37"></td>' +
			'</a><td style="vertical-align: middle;"><a id="hplSendQRCode" href="#", style="margin-bottom: 32px;" onclick="">Mail me mijn Gollie-code</a></td>' +
			'</tr></table></div>' +
			'<input type="hidden" name="tbhuid" id="tbhuid"><input type="hidden" name="tbhwt" id="tbhwt">' +
			'<table>' +
			'<tr class="{#0} {#1} {#2}"><td><label>Gebruikersnaam</label></td><td><label id="lblusername"></label></td></tr>' +
			'<tr class="{#0} {#1} {#2}"><td><label for="{#3}">{#4}</label></td><td><input class="validate required markasrequired" friendlyname="{#4}" name="{#3}" id="{#3}" type="text" maxlength="16"></td></tr>' +
			'<tr class="{#0} {#1} {#2}"><td><label for="{#5}">{#6}</label></td><td><input name="{#5}" id="{#5}" type="text" maxlength="16"></td></tr>' +
			'<tr class="{#0} {#1} {#2}"><td><label for="{#7}">{#8}</label></td><td><input class="validate required markasrequired" friendlyname="{#8}" name="{#7}" id="{#7}" type="text" maxlength="48"></td></tr>' +
			'<tr class="{#0}"><td><label for="{#9}">{#10}</label></td><td><input class="validate required markasrequired" friendlyname="{#10}" name="{#9}" id="{#9}" type="text" maxlength="32"></td></tr>' +
			'<tr class="{#0} {#1} {#2}"><td><label for="{#11}">{#12}</label></td><td><input type="radio" name="{#11}" id="{#13}" value="1" checked="checked"><label for="{#13}">Man</label><input type="radio" name="{#11}" id="{#14}" value="0"><label for="{#14}">Vrouw</label></td></tr>' +
			'<tr class="{#0}"><td><label for="{#15}">{#16}</label></td><td><input class="validate regex dialog-datepicker birthdate markasrequired" regex="^\\d{2}-\\d{2}-\\d{4}$" validationmsg="formaat: dd-mm-jjjj" friendlyname="{#16}" name="{#15}" id="{#15}" type="text"></td></tr>' +
			'<tr class="{#0} {#2}"><td><label for="{#17}">{#18}</label></td><td><input class="validate regex markasrequired" regex="^[^@]+@[^\\.@]+\\..+$" friendlyname="{#18}" name="{#17}" id="{#17}" type="text" maxlength="128"></td></tr>' +
			'<tr class="{#0} {#2}"><td><label for="{#19}" id="lblmobile">{#20}</label></td><td><input class="validate regex markasrequired" regex="^(00316|\\+316|06)[- ]?\\d{8}$" friendlyname="{#20}" name="{#19}" id="{#19}" type="text"></td></tr>' +
			'<tr class="{#0}"><td class="wrap" colspan="2"><span style="font-style:italic;">Laat onderstaande velden leeg om uw pincode ongewijzigd te laten</span></td></tr>' +
			'<tr class="{#0}"><td><label for="{#21}">{#22}</label></td><td><input class="validate regex" regex="^(\\d{4})?$" validationmsg="moet uit 4 cijfers bestaan" friendlyname="{#22}" name="{#21}" id="{#21}" type="password" maxlength="4" placeholder="0000"></td></tr>' +
			'<tr class="{#0}"><td><label for="{#23}">{#24}</label></td><td><input name="{#23}" id="{#23}" type="password" maxlength="4" placeholder="0000"></td></tr>' +
			'<tr class="{#0} {#1} {#2}"><td class="wrap" colspan="2"><span style="font-style:italic;">Laat onderstaande velden leeg om uw wachtwoord ongewijzigd te laten</span></td></tr>' +
			'<tr class="{#0} {#1} {#2}"><td><label for="{#25}">{#26}</label></td><td><input class="validate regex" regex="^(.{6,})?$" validationmsg="moet ten minste 6 karakters bevatten" friendlyname="{#26}" name="{#25}" id="{#25}" type="password" placeholder="min 6 karakters"></td></tr>' +
			'<tr class="{#0} {#1} {#2}"><td><label for="{#27}">{#28}</label></td><td><input name="{#27}" id="{#27}" type="password" placeholder="min 6 karakters"></td></tr>' +
			'<tr class="{#0} {#1} {#2}"><td colspan="2" class="wrap"><hr/><span style="font-style:italic;">Vul hieronder uw huidige wachtwoord in klik \'Ok\' om de wijzigingen op te slaan.</span></td></tr>' +
			'<tr class="{#0} {#1} {#2}"><td><label for="{#29}">{#30}</label></td><td><input class="validate minlength markasrequired" minlength="6" friendlyname="{#30}" name="{#29}" id="{#29}" type="password" placeholder="min 6 karakters"></td></tr>' +
			'</table></div>', 'customer', 'sales', 'administrator', 'tbvoorletters', 'Voorletters', 'tbtussenvoegsel', 'Tussenvoegsel', 'tbachternaam', 'Achternaam', 'tbwoonplaats', 'Woonplaats', 'rbsex', 'Geslacht', 'rbman', 'rbvrouw', 'tbgeboortedatum', 'Geboortedatum', 'tbemail', 'E-mail', 'tbmobile', 'Mobiel', 'tbpin', 'Nieuwe pincode', 'tbpinrepeat', 'Nieuwe pincode nogmaals', 'tbnewww', 'Nieuw wachtwoord','tbnewwwrepeat','Nieuw wachtwoord nogmaals','tbww','Huidig wachtwoord')
			,
	vendorsettings: $G.string.format(
			'<div style="font-size: 0.9em;" id="pnlvendorsettings">' +
			'<div style="font-size: 1.3em; margin-bottom: 12px;"><span class="clscompanyname"></span></div>' +
			'<input type="hidden" name="tbhuid" id="tbhuid"><input type="hidden" name="tbhwt" id="tbhwt">' +
			'<hr/>' +
			'<span style="font-size: 1.2em; text-decoration: underline;">Retourboekingen</span><br/>' +
			'<span class="explanation-inline" style="color: #008000;">Indien u retourboekingen toestaat heeft u tijdens het afrekenen de mogelijkheid een bedrag terug te storten in het Gollie-account van de klant, bijvoorbeeld als de klant het gekochte retour brengt.<br/>' +
			'Staat u retourboekingen niet toe, dan heeft u deze mogelijkheid niet. Dit kan van belang zijn als medewerkers die de betalingen afhandelen ook klanten zijn van </span><span class="explanation-inline clscompanyname" style="color: #008000;"></span><span class="explanation-inline" style="color: #008000;"> met een Gollie-account. Zij kunnen dan geen frauduleuze retourboekingen doen, b.v. naar hun eigen account.' +
			'</span><br/><br/>' +
			'<table>' +
			'<tr><td><input type="radio" name="{#0}" id="{#1}" value="0" checked="checked"><label for="{#1}">Retourboekingen NIET toestaan</label></td></tr>'+
			'<tr><td><input type="radio" name="{#0}" id="{#2}" value="1"><label for="{#2}">Retourboekingen WEL toestaan</label></td></tr>' +
			'</table></div>', 'rballowrefundchoice', 'rbdontallow', 'rballow')
			,
	registervendoruser: $G.string.format(
			'<div style="font-size: 0.9em;" id="pnlregistervendoruser">' +
			'<input type="hidden" name="tbhuid" id="tbhuid"><input type="hidden" name="tbhwt" id="tbhwt">' +
			'<table style="border: 1px solid black; margin: 0; padding: 0;" cellpadding="0" cellspacing="0">' +
			'<tr style="border-bottom: 1px solid black;"><td style="vertical-align: top; padding-right: 16px; border-bottom: 1px solid black;">' + 
			'<input type="radio" name="{#0}" id="{#1}" value="3" checked="checked"><b><label for="{#1}">Kassier</label></b></td>' +
			'<td class="wrap" style="vertical-align: top; border-bottom: 1px solid black; padding-bottom: 8px; padding-top: 0px;">Een kassier kan de volgende handelingen verrichten:' +
			'<ul><li>Betalingen afhandelen</li><li>De kas afsluiten</li></ul>' +
			'</td></tr>' +
			'<tr style="border-bottom: 1px solid black;"><td style="vertical-align: top; padding-right: 16px; border-bottom: 1px solid black;">' +
			'<input type="radio" name="{#0}" id="{#2}" value="2"><b><label for="{#2}">Verkoper</label></b></td>' +
			'<td class="wrap" style="vertical-align: top; border-bottom: 1px solid black; padding-bottom: 8px; padding-top: 0px;">Een verkoper kan de volgende handelingen verrichten:' +
			'<ul><li>Deals maken</li><li>Deals die hij zelf heeft gemaakt wijzigen en verwijderen</li></ul>' +
			'</td></tr>' +
			'<tr style="border-bottom: 1px solid black;"><td style="vertical-align: top; padding-right: 16px;">' +
			'<input type="radio" name="{#0}" id="{#3}" value="1"><b><label for="{#3}">Administrator</label></b></td>' +
			'<td class="wrap" style="vertical-align: top; padding-bottom: 8px; padding-top: 0px;">Een administrator kan de volgende handelingen verrichten:' +
			'<ul><li>Betalingen afhandelen</li><li>De kas afsluiten</li><li>Deals maken</li><li>Alle deals wijzigen en verwijderen</li><li>Dashboard inzien</li><li>Facturen inzien</li><li>Klantbeoordelingen inzien</li><li>Gebruikersadministratie voeren</li></ul>' +
			'</td></tr>' +
			'</table></div>','rbusertype','rbcashier','rbsales','rbadmin')
			,
	userfields: $G.string.format(
			'<div style="font-size: 0.9em;">' +
			'<div style="text-align: center; margin-bottom: 16px; font-size: 1.3em;"><span id="lblvendoruserrole" style="border-bottom: 2px solid black;"></span></div>' +
			'<table>' +
			'<tr><td><label for="{#0}">{#1}</label></td><td><input class="validate required markasrequired" friendlyname="{#1}" name="{#0}" id="{#0}" type="text" maxlength="16"></td></tr>' +
			'<tr><td><label for="{#2}">{#3}</label></td><td><input name="{#2}" id="{#2}" type="text" maxlength="16"></td></tr>' +
			'<tr><td><label for="{#4}">{#5}</label></td><td><input class="validate required markasrequired" friendlyname="Achternaam" name="{#4}" id="{#4}" type="text" maxlength="48"></td></tr>' +
			'<tr><td><label for="{#6}">{#7}</label></td><td><input type="radio" name="{#6}" id="{#8}" value="1" checked="checked"><label for="{#8}">Man</label><input type="radio" name="{#6}" id="{#9}" value="0"><label for="{#6}">Vrouw</label></td></tr>' +
			'<tr><td><label for="{#10}">{#11}</label></td><td><input class="validate lengthrange markasrequired" friendlyname="{#11}" minlength="6" name="{#10}" id="{#10}" type="text" maxlength="16" placeholder="max 16 karakters"></td></tr>' +
			'<tr><td><label for="{#12}">{#13}</label></td><td><input class="validate minlength markasrequired" minlength="6" friendlyname="{#13}" name="{#12}" id="{#12}" placeholder="min 6 karakters"></td></tr>' +
			'</table></div>', 'tbvoorletters', 'Voorletters', 'tbtussenvoegsel', 'Tussenvoegsel', 'tbachternaam', 'Achternaam', 'rbsex', 'Geslacht', 'rbman', 'rbvrouw', 'tbusername', 'Gebruikersnaam', 'tbww', 'Wachtwoord')
			,
	registerVendorUserSuccess: '<span>De gebruiker is toegevoegd.</span>'
			,
	resetVendorUserWW:
			'<input type="hidden" id="tbhuid" name="tbhuid"><input type="hidden" name="tbhwt" id="tbhwt">' +
			'<span>Reset wachtwoord voor: </span><span id="lblUserName" style="font-weight: bold;"></span><br/><br/>' +
			'<label for="tbww">Nieuw wachtwoord: </label><input class="validate minlength markasrequired" minlength="6" friendlyname="Wachtwoord" name="tbww" id="tbww" placeholder="min 6 karakters">'
			,
	resetVendorUserWWSuccess: '<span>Het wachtwoord is gewijzigd.</span>'
			,
	registerVendorForm:$G.string.format(
			'<div style="font-size: 0.9em;">' +
			'<span class="explanation" style="color: #008000;">Om uw bedrijf te registreren hebben wij uw 8-cijferig KVK-nummer nodig. Hiermee kunnen wij een aantal gegevens alvast voor u invullen.</span><br/>' +
			'<hr/>' +
			'<label for="{#0}">Uw {#1}: </label><input class="validate regex markasrequired" regex="^\\d{8}$" friendlyname="{#1}" name="{#0}" id="{#0}" maxlength="8" placeholder="12345678"><br/><br/>'
			, 'tbkvk', 'KvK-nummer')
			,
	registerVendorStep1: $G.string.format(
			'<div style="font-size: 0.9em;">' +
			'<div id="pnlFailedKvK" style="display: none; color: #A00000; font-style:italic; padding-bottom: 8px;"><span></span></div>' +
			'<table>' +
			'<tr><td><label>KvK nummer</label></td><td><label id="lblKvK"></label></td></tr>' +
			'<tr><td><label for="{#0}">{#1}</label></td><td><input class="validate required markasrequired" friendlyname="{#1}" name="{#0}" id="{#0}" type="text" maxlength="96"></td></tr>' +
			'<tr><td><label for="{#2}">{#3}</label></td><td><input class="validate required markasrequired" friendlyname="{#3}" name="{#2}" id="{#2}" type="text" maxlength="64"></td></tr>' +
			'<tr><td><label for="{#4}">{#5}</label></td><td><input class="validate regex markasrequired" regex="^\\d{4} ?[a-zA-Z]{2}$" friendlyname="{#5}" name="{#4}" id="{#4}" type="text"></td></tr>' +
			'<tr><td><label for="{#6}">{#7}</label></td><td><input class="validate required markasrequired" friendlyname="{#7}" name="{#6}" id="{#6}" type="text" maxlength="32"></td></tr>' +
			'<tr><td><label for="{#8}">{#9}</label></td><td><input class="validate regex" regex="^(((http|https):\\/\\/)?www\\..+\\.[A-Za-z]{2,10})?$" friendlyname="{#9}" name="{#8}" id="{#8}"></td></tr>' +
			'<tr><td><label for="{#10}">Bedrijfslogo</label></td><td><input type="file" name="{#10}" id="{#10}"></td></tr>' +
			'</table></div>' +
			'<div class="companylogo" id="pnlcompanylogo" style="margin: 24px;"></div>' +
			'<input id="tbcompanylogoimagetype" type="hidden"><input id="tbcompanylogoimagesize" type="hidden">'
			, 'tbbedrijfsnaam', 'Bedrijfsnaam', 'tbstraat', 'Adres', 'tbpostcode', 'Postcode', 'tbplaats', 'Plaats', 'tbwebsite', 'Website', 'tblogo')
			,
	registerVendorStep2: $G.string.format(
			'<div style="font-size: 0.9em;">' +
			'<span class="explanation" style="color: #008000;">De contactpersoongegevens worden door Gollie gebruikt om contact te zoeken met de business als dat nodig is. Daarnaast wordt de contactpersoon aangewezen als beheerder van de business op Gollie.nl en krijgt een beheerdersaccount toegewezen, waarmee de business op Gollie.nl beheerd kan worden.<br/>Dit beheerdersaccount is niet direct actief. Gollie.nl zal eerst de registratie verifiëren. U ontvangt een email op het adres dat u hieronder invult zodra het het account actief is.</span><br/>' +
			'<hr/>' +
			'<table>' +
			'<tr><td><label for="{#0}">{#1}</label></td><td><input class="validate required markasrequired" friendlyname="{#1}" name="{#0}" id="{#0}" type="text" maxlength="16"></td></tr>' +
			'<tr><td><label for="{#2}">{#3}</label></td><td><input name="{#2}" id="{#2}" type="text" maxlength="16"></td></tr>' +
			'<tr><td><label for="{#4}">{#5}</label></td><td><input class="validate required markasrequired" friendlyname="{#5}" name="{#4}" id="{#4}" type="text" maxlength="48"></td></tr>' +
			'<tr><td><label for="{#6}">{#7}</label></td><td><input type="radio" name="{#6}" id="{#8}" value="1" checked="checked"><label for="{#8}">Man</label><input type="radio" name="{#6}" id="{#9}" value="0"><label for="{#9}">Vrouw</label></td></tr>' +
			'<tr><td><label for="{#10}">{#11}</label></td><td><input class="validate regex markasrequired" regex="^[^@]+@[^\\.@]+\\..+$" friendlyname="{#11}" name="{#10}" id="{#10}" type="text" maxlength="128"></td></tr>' +
			'<tr><td><label for="{#12}">{#13}</label></td><td><input class="validate regex markasrequired" regex="^(0031|\\+31|0)[- ]?\\d{9}$" friendlyname="{#13}" name="{#12}" id="{#12}" type="text"></td></tr>' +
			'</table></div>', 'tbvoorletters', 'Voorletters', 'tbtussenvoegsel', 'Tussenvoegsel', 'tbachternaam', 'Achternaam', 'rbsex', 'Geslacht', 'rbman', 'rbvrouw', 'tbemail', 'E-mail', 'tbmobile', 'Telefoon'
			)
			,
	registerVendorStep3: $G.string.format(
			'<div style="font-size: 0.9em;">' +
			'<span class="explanation" style="color: #008000;">De factuurgegevens worden door Gollie gebruikt om de door de consumenten betaalde voorschotten aan u uit te betalen, en om de facturen op te maken. Deze worden verzonden naar het hier opgegeven e-mailadres.</span><br/>' +
			'<hr/>' +
			'<table>' +
			'<tr><td><label for="{#0}">{#1}</label></td><td><input class="validate required markasrequired" friendlyname="{#1}" name="{#0}" id="{#0}" type="text" maxlength="64"></td></tr>' +
			'<tr><td><label for="{#2}">{#3}</label></td><td><input class="validate regex markasrequired" friendlyname="{#3}" regex="^\\d{4} ?[a-zA-Z]{2}$" name="{#2}" id="{#2}" type="text" maxlength="10"></td></tr>' +
			'<tr><td><label for="{#4}">{#5}</label></td><td><input class="validate required markasrequired" friendlyname="{#5}" name="{#4}" id="{#4}" type="text" maxlength="32"></td></tr>' +
			'<tr><td><label for="{#6}">{#7}</label></td><td><input class="validate regex markasrequired" regex="^[^@]+@[^\\.@]+\\..+$" friendlyname="{#7}" name="{#6}" id="{#6}" type="text" maxlength="128"></td></tr>' +
			'<tr><td><label for="{#8}">{#9}</label></td><td><input class="validate required markasrequired" friendlyname="{#9}" name="{#8}" id="{#8}" type="text" maxlength="96"></td></tr>' +
			'<tr><td><label for="{#10}">{#11}</label></td><td><input class="validate regex markasrequired" regex="^[A-Za-z]{2}\\d{2}[A-Za-z0-9]{1,30}" friendlyname="{#11}" name="{#10}" id="{#10}"><a href="http://www.ibanconverter.com/" target="_blank" class="button">IBAN hulp...</a></td></tr>' +
			'</table><br/></div>', 'tbbillingstreet', 'Straat/postbus', 'tbbillingzipcode', 'Postcode', 'tbbillingplaats', 'Plaats', 'tbbillingemail', 'E-mail', 'tbbankname', 'Tenaamstelling bank', 'tbiban', 'IBAN rekeningnummer')
			,
	registerVendorStep4: '<div style="font-size: 0.9em;">' +
			'<span class="explanation" style="color: #008000;">Controleer alstublieft onderstaande gegevens. Als deze correct zijn klikt u op \'Opslaan\' om uw registratie te voltooien. Lees ook de voorwaarden en kruis het bijbehorende vinkje aan om aan te geven dat u hiermee akkoord gaat.<br/>Klik op \'Vorige\' als u nog iets wil wijzigen.</span><br/>' +
			'<hr/>' +
			'<div style="border: 1px solid black; padding: 8px;"><input name="cbconditions" id="cbconditions" type="checkbox"><label for="cbconditions">Ik ga akkoord met&nbsp;</label><a class="common" href="/Conditions.aspx" target="_blank">de voorwaarden.</a></div>' +
			'<br/>' +
			'<table style="width: 100%; border-collapse: collapse;">' +
			'<tr><td colspan="2"><span class="summaryheader">Bedrijfsgegevens</span></td>' +
			'<td colspan="2"><span class="summaryheader">Contactpersoongegevens</span></td>' +
			'</tr><tr>' +
			'<td><span>Bedrijfsnaam</span></td><td style="width: 224px;"><span class="summaryvalue" id="lblcheckcompanyname"></span></td>' +
			'<td><span>Voorletters</span></td><td style="width: 224px;"><span class="summaryvalue" id="lblcheckinitials"></span></td>' +
			'</tr><tr>' +
			'<td><span>Adres</span></td><td style="width: 224px;"><span class="summaryvalue" id="lblcheckstreet"></span></td>' +
			'<td><span>Tussenvoegsel</span></td><td style="width: 224px;"><span class="summaryvalue" id="lblcheckinfix"></span></td>' +
			'</tr><tr>' +
			'<td><span>Postcode</span></td><td style="width: 224px;"><span class="summaryvalue" id="lblcheckzipcode"></span></td>' +
			'<td><span>Achternaam</span></td><td style="width: 224px;"><span class="summaryvalue" id="lblchecklastname"></span></td>' +
			'</tr><tr>' +
			'<td><span>Plaats</span></td><td style="width: 224px;"><span class="summaryvalue" id="lblcheckcity"></span></td>' +
			'<td><span>Geslacht</span></td><td style="width: 224px;"><span class="summaryvalue" id="lblchecksex"></span></td>' +
			'</tr><tr>' +
			'<td><span>Website</span></td><td style="width: 224px;"><span class="summaryvalue" id="lblcheckwebsite"></span></td>' +
			'<td><span>E-mail</span></td><td style="width: 224px;"><span class="summaryvalue" id="lblcheckemail"></span></td>' +
			'</tr><tr>' +
			'<td><span>KvK</span></td><td><span class="summaryvalue" id="lblcheckkvk"></span></td>' +
			'<td><span>Telefoon</span></td><td style="width: 224px;"><span class="summaryvalue" id="lblcheckmobile"></span></td>' +
			'</tr>' +
			'</table>' +
			'<br/>' +
			'<table style="width: 100%; border-collapse: collapse;"><tr><td colspan="2"><span class="summaryheader">Factuurgegevens</span></td></tr>' +
			'<tr><td><span>Adres/Postbus</span></td><td><span class="summaryvalue" id="lblcheckbillingstreet"></span></td></tr>' +
			'<tr><td><span>Postcode</span></td><td><span class="summaryvalue" id="lblcheckbillingzipcode"></span></td></tr>' +
			'<tr><td><span>Plaats</span></td><td><span class="summaryvalue" id="lblcheckbillingcity"></span></td></tr>' +
			'<tr><td><span>E-mail</span></td><td><span class="summaryvalue" id="lblcheckbillingemail"></span></td></tr>' +
			'<tr><td><span>Tenaamstelling bank</span></td><td><span class="summaryvalue" id="lblcheckbillingbankname"></span></td></tr>' +
			'<tr><td><span>Rekeningnummer</span></td><td><span class="summaryvalue" id="lblcheckbillingiban"></span></td></tr>' +
			'</table>' +
			'<div class="companylogo" id="pnlsummarycompanylogo" style="margin: 24px;">' +
			'</div>'
			,
	registerVendorSuccess: '<span>Uw organisatie is geregistreerd bij Gollie.nl.<br /><br />' +
			'Voor u is alvast een beheerdersaccount aangemaak, waarvan de inlognaam u zojuist is toegezonden.<br />' +
			'Dit beheerdersaccount is niet direct actief. U kunt dus nog niet inloggen met dit account. Gollie.nl zal eerst de registratie verifiëren. Dit neemt doorgaans enkele werkdagen in beslag.<br />' +
			'<br/>' +
			'U ontvangt een e-mail zodra het account is geactiveerd. Ook het bijbehorende wachtwoord zal u dan bekend worden gemaakt.<br />' +
			'<br/><br/>' +
			'Wij danken u hartelijk voor de inschrijving!' +
			'</span>'
}

$G.web.dialogs = {
	login: {
		form: {
			title: 'Inloggen',
			html:	$G.web.dialoghtml.login,
			buttons: $G.web.dialog.buttons.OkCancel,
			ajaxCall: "userLogin",
			ajaxArg: function (f) { return { tokenUser: f.username, ww: f.ww }; },
			clientValidate: function (f) {
				var errors = [];
				$G.web.dialog.clientValidate(f, errors);
				return errors;
			},
			resetWW: function () {
				$G.web.dialog.replaceDialog('resetWW');
			}
		}
	},

	resetWW: {
		form: {
			title: 'Wachtwoord vergeten',
			html: $G.web.dialoghtml.resetWW,
			buttons: $G.web.dialog.buttons.OkCancel,
			ajaxCall: 'resetWW',
			ajaxArg: function (f) { return { tokenUser: f.username }; },
			clientValidate: function (f) {
				var errors = [];
				$G.web.dialog.clientValidate(f, errors);

				return errors;
			},
			nextStateOnSuccess: 'resetWWConfirm'
		},
		resetWWConfirm: {
			title: 'Wachtwoord gewijzigd',
			html: $G.web.dialoghtml.resetWWConfirm,
			buttons: $G.web.dialog.buttons.Close
		},

	},

	registerObj: {
		form: {
			title: 'Registreren',
			html: $G.web.dialoghtml.registerObj,
			buttons: $G.web.dialog.buttons.NextCancel,
			nextStateOnSuccess: {
				replacedialog: function (f) {
					return f.rbregoption == "1" ? "registerConsumer" : "registerVendor";
				}
			}
		}
	},

	registerConsumer: {
		form: {
			title: 'Registeren als consument',
			html: $G.web.dialoghtml.registerConsumer,
			buttons: $G.web.dialog.buttons.OkCancel,
			ajaxCall: "registerConsumer",
			ajaxArg: function (f) {
				return {
					tokenUser: f.tbusername,
					initials: f.tbvoorletters,
					infix: f.tbtussenvoegsel,
					lastname: f.tbachternaam,
					city: f.tbwoonplaats,
					email: f.tbemail,
					mobile: f.tbmobile,
					sex: f.rbsex,
					birthdate: f.tbgeboortedatum,
					ww: f.tbww,
					pin: f.tbpin
				};
			},
			clientValidate: function (f) {
				var errors = [];
				$G.web.dialog.clientValidate(f, errors);

				//impromptu doesn't seem to recognize checkbox fields
				if ($('#cbconditions').prop('checked') == false) errors.push('U dient akkoord te gaan met de voorwaarden');

				if (f.tbww != f.tbwwrepeat) errors.push("'Wachtwoord' en 'Wachtwoord nogmaals' komen niet overeen");
				if (f.tbpin != f.tbpinrepeat) errors.push("'Pincode' en 'Pincode nogmaals' komen niet overeen");
				return errors;
			},
			nextStateOnSuccess: 'registersuccess'
		},
		registersuccess: {
			title: 'Registratie gelukt',
			html: $G.web.dialoghtml.registersuccess,
			buttons: $G.web.dialog.buttons.Close,
			nextStateOnSuccess: '/Default.aspx'
		},
	},

	changeprofile: {
		form: {
			title: 'Mijn gegevens',
			html: $G.web.dialoghtml.changeprofile,
			buttons: $G.web.dialog.buttons.OkCancel,
			preparehtml: function (dialog, jqoFrom, jqoTo) {
				$G.web.ajax['getUserProfile']({qrcode: "1"}, $G.web.dialogs.changeprofile.form.prepareajaxsuccess, $G.web.dialogs.changeprofile.form.prepareajaxfail);
			},
			prepareajaxsuccess: function (msg) {
				var ui = msg.d.Ui;
				var role = ui.RoleId;
				var pnl = $('#pnlchangeprofile');

				$('#lblusername', pnl).text(ui.Gebruikersnaam);
				$('#tbhuid', pnl).val(ui.Id);
				$('#tbhwt', pnl).val(ui.WebToken);
				$('#tbvoorletters', pnl).val(ui.Voorletters);
				$('#tbtussenvoegsel', pnl).val(ui.Tussenvoegsel);
				$('#tbachternaam', pnl).val(ui.Achternaam);
				$('#tbwoonplaats', pnl).val(ui.Woonplaats);
				$('#tbhuid', pnl).val(ui.Id);
				$('input[name="rbsex"]', pnl).val([ui.Geslacht ? '1' : '0']);
				$('#tbgeboortedatum', pnl).val(msg.d.FormattedBirthdate);
				$('#tbemail', pnl).val(ui.Email);
				$('#tbmobile', pnl).val(ui.Telefoon);

				if (role != 4) {
					$('#lblmobile', pnl).html('Telefoon');
					$('#tbmobile', pnl).attr('regex', '^(0031|\\+31|0)\\d{9}').attr('friendlyname', 'Telefoon');
				}

				$('tr', pnl).each(function() {
					if (
						($(this).hasClass("administrator") == false && role == 1)
						|| ($(this).hasClass("sales") == false && role == 2)
						|| ($(this).hasClass("customer") == false && role == 4)
						)
					{
						$(this).hide();
						$(this).find('input').removeClass("validate");
					}
				});

				if (role == 4) {
					$('#imgQRThumbnail', pnl).attr('src', msg.d.QRCodeSrc);
					$('#hplSendQRCode', pnl).click(function() {
						$G.web.ajax.sendCode(
										{ tokenUser: ui.Id, token: ui.WebToken },
										function (msg) { alert('Uw Gollie-code is verstuurd') },
										function (xhr, status, error) { alert('Het versturen van uw Gollie-code is mislukt') }
										);
					});
				}

				pnl.show();
				
			},
			prepareajaxfail: function (error) {
				var errors = ['Fout bij ophalen gebruikersprofiel:', error.errorMessage];
				$G.web.dialog.clientValidationFail(errors, $G.web.dialogs.changeprofile.form);
			},
			ajaxCall: 'updateUser',
			ajaxArg: function (f) {
				return {
					tokenUser: f.tbhuid,
					token: f.tbhwt,
					initials: f.tbvoorletters,
					infix: f.tbtussenvoegsel,
					lastname: f.tbachternaam,
					city: f.tbwoonplaats,
					email: f.tbemail,
					mobile: f.tbmobile,
					sex: f.rbsex,
					birthdate: f.tbgeboortedatum,
					newww: f.tbnewww,
					newwwrepeat: f.tbnewwwrepeat,
					pin: f.tbpin,
					pinrepeat: f.tbpinrepeat,
					ww: f.tbww
				};
			},
			clientValidate: function (f) {
				var errors = [];
				$G.web.dialog.clientValidate(f, errors);

				if (f.tbnewww != f.tbnewwwrepeat) errors.push("'Nieuw wachtwoord' en 'Nieuw wachtwoord nogmaals' komen niet overeen");
				if (f.tbpin && f.tbpin != f.tbpinrepeat) errors.push("'Pincode' en 'Pincode nogmaals' komen niet overeen");
				return errors;
			},
			nextStateOnSuccess: 'changeprofilesuccess'
		},
		changeprofilesuccess: {
			title: 'Profiel gewijzigd',
			html: '<span>Uw gegevens zijn gewijzigd.</span>',
			buttons: $G.web.dialog.buttons.Close,
		}
	},

	vendorsettings: {
		form: {
			title: 'Instellingen',
			html: $G.web.dialoghtml.vendorsettings,
			buttons: $G.web.dialog.buttons.OkCancel,
			preparehtml: function (dialog, jqoFrom, jqoTo) {
				$G.web.ajax['getVendorSettings']({}, $G.web.dialogs.vendorsettings.form.prepareajaxsuccess, $G.web.dialogs.vendorsettings.form.prepareajaxfail);
			},
			prepareajaxsuccess: function (msg) {
				var ui = msg.d.Ui;
				var ven = ui.VendorInfo;
				var role = ui.RoleId;
				var pnl = $('#pnlvendorsettings');

				$('.clscompanyname', pnl).html(ven.BedrijfsNaam);
				$('#tbhuid', pnl).val(ui.Id);
				$('#tbhwt', pnl).val(ui.WebToken);
				$('input[name="rballowrefundchoice"]', pnl).val([ven.AllowRefund ? '1' : '0']);
			},
			prepareajaxfail: function (error) {
				var errors = ['Fout bij ophalen instellingen:', error.errorMessage];
				$G.web.dialog.clientValidationFail(errors, $G.web.dialogs.vendorsettings.form);
			},
			ajaxCall: 'updateVendorSettings',
			ajaxArg: function (f) {
				return {
					tokenUser: f.tbhuid,
					token: f.tbhwt,
					allowrefund: f.rballowrefundchoice
				};
			},
			nextStateOnSuccess: 'vendorsettingssuccess'
		},
		vendorsettingssuccess: {
			title: 'Instellingen gewijzigd',
			html: '<span>De instellingen zijn gewijzigd.</span>',
			buttons: $G.web.dialog.buttons.Close,
		}
	},

	registervendoruser: {
		form: {
			title: 'Kies het type gebruiker',
			html: $G.web.dialoghtml.registervendoruser,
			preparehtml: function (dialog, jqoFrom, jqoTo) {
				$G.web.ajax['getUserProfile']({}, $G.web.dialogs.registervendoruser.form.prepareajaxsuccess, $G.web.dialogs.registervendoruser.form.prepareajaxfail);
			},
			prepareajaxsuccess: function (msg) {
				var ui = msg.d.Ui;
				var pnl = $('#pnlregistervendoruser');

				$('#tbhuid', pnl).val(ui.Id);
				$('#tbhwt', pnl).val(ui.WebToken);
			},
			prepareajaxfail: function (error) {
				var errors = ['Fout bij ophalen gebruikersprofiel:', error.errorMessage];
				$G.web.dialog.clientValidationFail(errors, $G.web.dialogs.registervendoruser.form);
			},
			buttons: $G.web.dialog.buttons.NextCancel,
			nextStateOnSuccess: 'userfields'
		},
		userfields: {
			title: 'Gegevens invullen',
			html: $G.web.dialoghtml.userfields,
			preparehtml: function (dialog, jqoFrom, jqoTo) {
				var r = $('input:radio[name="rbusertype"]:checked', jqoFrom).val();
				var role = (r == '1' ? 'Administrator' : r == '2' ? 'Verkoper' : 'Kassier');
				$('#lblvendoruserrole', jqoTo).html('Rol: <b>' + role + '</b>');
			},

			buttons: $G.web.dialog.buttons.PreviousSaveCancel,
			defaultButton: 1,
			focus: 1,
			clientValidate: function (f) {
				var errors = [];
				$G.web.dialog.clientValidate(f, errors);

				return errors;
			},
			ajaxCall: 'registerVendorUser',
			ajaxArg: function (f) {
				return {
					tokenUser: f.tbhuid,
					token: f.tbhwt,
					usertype: f.rbusertype,
					initials: f.tbvoorletters,
					infix: f.tbtussenvoegsel,
					lastname: f.tbachternaam,
					email: f.tbemail,
					mobile: f.tbmobile,
					sex: f.rbsex,
					username: f.tbusername,
					ww: f.tbww,
					role: f.rbusertype
				};
			},
			previousState: 'form',
			nextStateOnSuccess: 'registerVendorUserSuccess'
		},
		registerVendorUserSuccess: {
			title: 'Gebruiker toegevoegd',
			html: $G.web.dialoghtml.registerVendorUserSuccess,
			buttons: $G.web.dialog.buttons.Close,
		}
	},

	resetVendorUserWW: {
		form: {
			title: 'Reset wachtwoord',
			html:  $G.web.dialoghtml.resetVendorUserWW,
			buttons: $G.web.dialog.buttons.OkCancel,
			clientValidate: function (f) {
				var errors = [];
				$G.web.dialog.clientValidate(f, errors);

				return errors;
			},
			ajaxCall: 'resetVendorUserWW',
			ajaxArg: function (f) {
				return {
					tokenUser: f.tbhuid,
					token: f.tbhwt,
					username: $("#lblUserName").text(),
					ww: f.tbww,
				};
			},
			nextStateOnSuccess: 'resetVendorUserWWSuccess'
		},

		resetVendorUserWWSuccess: {
			title: 'Wachtwoord gewijzigd',
			html: $G.web.dialoghtml.resetVendorUserWWSuccess,
			buttons: $G.web.dialog.buttons.Close,
			reload: false
		}
	},

	registerVendor: {
		form: {
			title: 'Registeer uw onderneming,  1 van 5',
			html: $G.web.dialoghtml.registerVendorForm,
			buttons: $G.web.dialog.buttons.NextCancel,
			clientValidate: function (f) {
				var errors = [];
				$G.web.dialog.clientValidate(f, errors);

				if (errors.length == 0)
					$('.clientside-dialog input[type="text"]').val('');

				return errors;
			},
			ajaxCall: 'initKvK',
			ajaxArg: function (f) {
				return { token: f.tbkvk };
			},
			nextStateOnSuccess: 'registerVendorStep1'
		},
		registerVendorStep1: {
			title: 'Uw bedrijfsgegevens, 2 van 5',
			html: $G.web.dialoghtml.registerVendorStep1,
			buttons: $G.web.dialog.buttons.PreviousNextCancel,
			preparehtml: function (dialog, jqoFrom, jqoTo) {
				var msg = dialog['registerVendorStep1'].msg;
				if (msg.state != 0)
					return;

				msg.state = 1;
				msg = msg.d;
				$('#tblogo', jqoTo).off('change').on('change', $G.web.dialogs.registerVendor.registerVendorStep1.logochange);
				
				var pnlFailed = $('#pnlFailedKvK', jqoTo);
				pnlFailed.hide();

				$('#lblKvK', jqoTo).text(msg.KvK);

				var errMsg = '';
				if (typeof (msg.FailedMsg) != 'undefined' && msg.FailedMsg.length > 0)
					errMsg = msg.FailedMsg;
				else {
					if (typeof (msg.ErrorMessage) != 'undefined' && msg.ErrorMessage.length > 0)
						errMsg = msg.ErrorMessage;
				}
				if (errMsg.length > 0) {
					$('span', pnlFailed).html(errMsg);
					pnlFailed.show();
				}
				else {
					var billingState = $.prompt.getState('registerVendorStep3');
					$('#tbbillingstreet', billingState).val(msg.Street);
					$('#tbbankname', billingState).val(msg.Name);
					$('#tbbillingzipcode', billingState).val(msg.ZipCode);
					$('#tbbillingplaats', billingState).val(msg.City);

					$('#tbbedrijfsnaam', jqoTo).val(msg.Name);
					$('#tbstraat', jqoTo).val(msg.Street);
					$('#tbpostcode', jqoTo).val(msg.ZipCode);
					$('#tbplaats', jqoTo).val(msg.City);
				}
			},
			nextStateOnSuccess: 'registerVendorStep2',
			previousState: 'form',
			defaultButton: 1,
			focus: 1,
			clientValidate: function (f) {
				var errors = [];
				var type = $('#tbcompanylogoimagetype').val();
				var size = Number($('#tbcompanylogoimagesize').val());

				$G.web.dialog.clientValidate(f, errors);

				if (type != '' && (/image\/(gif|jpeg|pjpeg|png)/.test(type) == false || size > 1024 * 1024))
					errors.push('Het logo dient een gif, png of jpg te zijn en kleiner dan 1Mb');

				return errors;
			},

			logochange: function (e) {
				$('.companylogo').empty();
				$('#tbcompanylogoimagetype').val('');
				$('#tbcompanylogoimagesize').val('');

				if (typeof (window.FileReader) == 'undefined') { //File api not supported
					$('.companylogo').append('<span style="color: #a00000;">Uw browser ondersteunt het bijvoegen van het logo helaas niet.<br/>Indien gewenst kunt u uw logo naar ons mailen. Nadat uw registratie volledig is verwerkt, zorgen wij voor de juiste verwerking van uw logo.</span>');
				}
				else {
					var file = this.files[0];

					$('#tbcompanylogoimagetype').val(file.type == "" ? "Unknown" : file.type);
					$('#tbcompanylogoimagesize').val(file.size);

					if (file.type.match(/image.*/)) {

						var reader = new FileReader();

						reader.onload = function (e) {
							var img = new Image();
							img.onload = function () {
								var maxW = 300;
								var maxH = 200;
								var xR = img.width / maxW;
								var yR = img.height / maxH;
								var r = Math.max(xR, yR);
								var nnx = Math.floor(img.width / r);
								var nny = Math.floor(img.height / r);
								img.width = nnx;
								img.height = nny;
								$('.companylogo').append(img);
							}
							img.src = reader.result;
						}
						reader.readAsDataURL(file);
					}
				}
			}
		},
		registerVendorStep2: {
			title: 'Uw contactgegevens,  3 van 5',
			html: $G.web.dialoghtml.registerVendorStep2,
			buttons: $G.web.dialog.buttons.PreviousNextCancel,
			defaultButton: 1,
			focus: 1,
			clientValidate: function (f) {
				var errors = [];
				$G.web.dialog.clientValidate(f, errors);

				return errors;
			},
			nextStateOnSuccess: 'registerVendorStep3',
			previousState: 'registerVendorStep1',
		},
		registerVendorStep3: {
			title: 'Uw factuurgegevens, 4 van 5',
			html: $G.web.dialoghtml.registerVendorStep3,
			buttons: $G.web.dialog.buttons.PreviousNextCancel,
			defaultButton: 1,
			focus: 1,
			clientValidate: function (f) {
				var errors = [];
				$G.web.dialog.clientValidate(f, errors);

				return errors;
			},
			nextStateOnSuccess: 'registerVendorStep4',
			previousState: 'registerVendorStep2',
		},
		registerVendorStep4: {
			title: 'Controle, 5 van 5',
			html: $G.web.dialoghtml.registerVendorStep4,
			preparehtml: function (dialog, jqoFrom, jqoTo) {
				var msg = dialog['registerVendorStep1'].msg.d;
				var jqoCompany = $.prompt.getState('registerVendorStep1');
				var jqoContact = $.prompt.getState('registerVendorStep2');
				var jqoBilling = $.prompt.getState('registerVendorStep3');
				$('#lblcheckkvk', jqoTo).text(msg.KvK);
				$G.web.dialog.helpers.input2label(jqoCompany, jqoTo, { '#tbbedrijfsnaam': '#lblcheckcompanyname', '#tbstraat': '#lblcheckstreet', '#tbpostcode': '#lblcheckzipcode', '#tbplaats': '#lblcheckcity', '#tbwebsite': '#lblcheckwebsite' });
				$G.web.dialog.helpers.input2label(jqoContact, jqoTo, { '#tbvoorletters': '#lblcheckinitials', '#tbtussenvoegsel': '#lblcheckinfix', '#tbachternaam': '#lblchecklastname', '#tbemail': '#lblcheckemail', '#tbmobile': '#lblcheckmobile' });
				$G.web.dialog.helpers.input2label(jqoBilling, jqoTo, { '#tbbillingstreet': '#lblcheckbillingstreet', '#tbbillingzipcode': '#lblcheckbillingzipcode', '#tbbillingplaats': '#lblcheckbillingcity', '#tbbillingemail': '#lblcheckbillingemail', '#tbbankname': '#lblcheckbillingbankname', '#tbiban': '#lblcheckbillingiban' });

				$('#lblchecksex', jqoTo).text($('#rbman', jqoContact).prop('checked') ? "Man" : "Vrouw");
			},
			buttons: $G.web.dialog.buttons.PreviousSaveCancel,
			defaultButton: 1,
			focus: 1,
			clientValidate: function (f) {
				var errors = [];

				//impromptu doesn't seem to recognize checkbox fields
				if ($('#cbconditions').prop('checked') == false) errors.push('U dient akkoord te gaan met de voorwaarden');
				return errors;
			},

			ajaxCall: 'registervendor',
			ajaxArg: function (f) {
				return {
					token: $("#lblcheckkvk").text(),
					companyname: f.tbbedrijfsnaam,
					address: f.tbstraat,
					zipcode: f.tbpostcode,
					city: f.tbplaats,
					country: 'Nederland',
					website: f.tbwebsite,
					initials: f.tbvoorletters,
					infix: f.tbtussenvoegsel,
					lastname: f.tbachternaam,
					sex: f.rbsex,
					email: f.tbemail,
					mobile: f.tbmobile,
					billingname: f.tbbankname,
					billingcountry: 'Nederland',
					billingaccount: f.tbiban,
					billingaddress: f.tbbillingstreet,
					billingzipcode: f.tbbillingzipcode,
					billingcity: f.tbbillingplaats,
					billingemail: f.tbbillingemail,
					logodata: $G.web.dialogs.registerVendor.registerVendorStep4.getlogodata(),
					logomimetype: $('#tbcompanylogoimagetype').val()
				};
			},

			nextStateOnSuccess: 'registerVendorSuccess',
			previousState: 'registerVendorStep3',
			getlogodata: function () {
				var img = $('.companylogo:first img');
				if (img.length != 0) {
					return img.attr('src');
				}
				return '';
			}
		},
		registerVendorSuccess: {
			title: 'Registratie voltooid',
			html: $G.web.dialoghtml.registerVendorSuccess,
			buttons: $G.web.dialog.buttons.Close,
		}
	},
};